package com.ys.peony.view.adapter;

import android.support.v7.util.DiffUtil;

import java.util.List;

/**
 * Created by 59153 on 2017/8/21.
 * 描述：用户recyclerview列表对比新旧数据
 */

public class AdapterDiffCallback<T> extends DiffUtil.Callback{
    List<String> mOldList;
    List<String> mNewList;

    public AdapterDiffCallback(List<String> oldList,List<String> newList) {
        mOldList = oldList;
        mNewList = newList;
    }
    @Override
    public int getOldListSize() {
        return mOldList.size();
    }

    @Override
    public int getNewListSize() {
        return mNewList.size();
    }

    @Override
    public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) {
        return mOldList.get(oldItemPosition).getClass().equals(mNewList.get(newItemPosition).getClass());
    }

    @Override
    public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) {
        String oldStr = mOldList.get(oldItemPosition);
        String newStr = mNewList.get(newItemPosition);
        return oldStr.equals(newStr);
    }
}
